#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);

	int tmp;
	int km = 0;
	int i;
	for (i = 1; n > 10; i = i * 9)
	{
		tmp = n % 10;
		if (tmp < 4)
			;
		else
			tmp = (tmp - 1) * i;

		km = km + tmp;
		n = n / 10;
	}

	if (n < 4)
		;
	else
		n = (n - 1) * i;
	
	km = km + n;
	printf("%d", km);
	return 0;
}